package cn.itcast.controller;

import cn.itcast.domain.Account1;
import cn.itcast.domain.kefang;
import cn.itcast.domain.kehu;
import cn.itcast.service.impl.kefangService;
import cn.itcast.service.impl.kehuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping(path ="/user")
public class LoginController {
    @Autowired
    private kehuService kehuservice;
    @Autowired
    private kefangService kefangservice;

    @RequestMapping(path = "/jump")
    public String jump(Model model, HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<kehu> list = kehuservice.findAllkehu();
        model.addAttribute("list", list);
        return "User_index";
    }
//    验证
    @RequestMapping(path="/Login")
    public void Login(Account1 account, HttpServletRequest request, HttpServletResponse response) throws IOException {
        String loginName = account.getUsername();
        String password = account.getPassword();
        String checkcode = account.getCheckcode();
        String Code = (String) request.getSession().getAttribute("Code");
        //校验验证码
        if(checkcode.equals(Code)||true) {
            if(true||loginName.equals("admin")&&password.equals("123456")) {
                response.sendRedirect(request.getContextPath()+"/user/jump");
                return ;
            }else {
                response.sendRedirect(request.getContextPath()+"/Manager_login.jsp");
                return ;
            }
        }else {
            response.sendRedirect(request.getContextPath()+"/Manager_login.jsp");
            return ;
        }
    }
}
